from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from meiduo_admin.serializer.admin_user import AdminSerializer
from meiduo_admin.serializer.groups import GroupSerializer
from meiduo_admin.utils import PageNum
from django.contrib.auth.models import Group
from users.models import User

# 管理员表的增删改查
class AdminUserView(ModelViewSet):

    # 指定权限
    permission_classes = [IsAdminUser]
    # 指定序列化器
    serializer_class = AdminSerializer
    # 指定查询集
    queryset = User.objects.filter(is_staff=True)
    # 指定分页器
    pagination_class = PageNum

    def simple(self,request):
        # 查询所有用户组
        user = Group.objects.all()
        # 返回所有用户组
        ser = GroupSerializer(user,many=True)
        return Response(ser.data)